package cn.hycat.leetcode.easy;

import java.util.Arrays;
import java.util.List;

/**
 * @author 吕泽浩业
 * @version 1.0
 */
public class L151颠倒字符串中的单词 {
    public static void main(String[] args) {
        System.out.println(reverseWords("a good   example"));
    }
    public static String reverseWords(String s) {
        s = s.trim();
        //正则表达式去除空格
        String[] strs = s.split("\\s+");
        StringBuilder builder = new StringBuilder();

        for(int i = strs.length - 1; i >= 0; i--) {
            builder.append(strs[i]);
            builder.append(i == 0 ? "" : " ");
        }
        return builder.toString();
    }
}
